﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace TheOutfield.UmbExt.UniversalMediaPicker.Providers.Qik
{
    public class QikProvider : AbstractProvider
    {
        private QikConfigControl _configControl;

        public QikProvider()
        { }

        public QikProvider(string config)
            : base(config)
        {
            Service = new QikService(config);
        }

        public override string Alias
        {
            get { return "Qik"; }
        }

        public override Interfaces.IConfigControl ConfigControl
        {
            get 
            {
                if (_configControl == null)
                    _configControl = new QikConfigControl(Config);

                return _configControl;
            }
        }

        public override Interfaces.ICreateControl CreateControl
        {
            get { throw new NotImplementedException(); }
        }

        public QikService Service { get; private set; }

        public override MediaItem GetMediaItemById(string id)
        {
            var videoId = 0;

            return int.TryParse(id, out videoId) ? Service.GetVideo(videoId).ToMediaItem() : null;
        }

        public override IList<MediaItem> GetMediaItems(string parentId)
        {
            var videos = Service.GetVideos();

            return videos.Select(video => video.ToMediaItem()).ToList();
        }
    }
}